/**
 * Created by Administrator on 2016/6/28.
 */
//模拟媒体查询

//强制用户浏览器全屏
$(document).ready(function(){
    function exitFullscreen() {
        if(document.exitFullscreen) {
            document.exitFullscreen();
        } else if(document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } else if(document.webkitExitFullscreen) {
            document.webkitExitFullscreen();
        }
    }
// 退出全屏模式!
    exitFullscreen();
});

//定义全局变量
//接口统一请求地址参数
var commonval = "http://pre.haotoufa.com";
var length = commonval.length;
//定义session应用变量
var session_id = sessionStorage.session_id;
var user_token = sessionStorage.user_token;
var u_id = sessionStorage.u_id;
//定义公共参数
var postArray = {user_token:user_token, device:"wap",session_id:session_id};

//默认图片路径
var userIconDefault = '../images/userDefault.png';

//定义全局方法
//弹窗
function createWindow(msg) {
    var window =$("<section class='showMsg'></section>");
    var show = "<p>"+msg+"</p>";
    window.append(show);
    $("body").append(window);
    setTimeout("$('.showMsg').remove()",3000);
}
//跳转函数
function jumpPage(url){
    location.href=url;
}
//获取字符串中的值
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

//定义默认方法集
$(document).ready(function(){
    var $width = $(window).width();
    var $height = $(window).height();
    //定义顶部返回按钮
    $("header img:first-child").click(function(e){
        history.go(-1);
        e.stopPropagation();
    })
    ////固定顶部标题位置

    //定义footer默认返回
    $("footer section:nth-child(1)").click(function(){
        jumpPage("index.html");
    })
    $("footer section:nth-child(2)").click(function(){
        if(u_id){
            jumpPage("consult.html");
        }else{
            jumpPage("noLoginInConsult.html?jump=2");
        }
    })
    $("footer section:nth-child(3)").click(function(){
        location.href = "mine.html";
    })
    //定义公共底部位置
    $("footer").css("top",$height-172);
    //防止底部错位
    $("footer").css("display","block");
    //定义公共遮罩大小
    $(".mask").css({'height':$height,'width':$width});
    //定义左右选择弹窗函数集

});
//获取下载信息
$(document).ready(function(){
    $.post(commonval+"/share_info",postArray,function(data){
        if(data.status == 1){
          sessionStorage.ios = data.data.ios;
            sessionStorage.android = data.data.android;
        }
    })
    $(".download").click(function(){
        var ua = navigator.userAgent.toLowerCase();
        if (/iphone|ipad|ipod/.test(ua)) {
            location.href=sessionStorage.ios;
        } else if (/android/.test(ua)) {
            location.href=sessionStorage.android;
        }
    })
});
//待处理订单数目逻辑
$(document).ready(function(){
    if(session_id){
        postArray.u_id = u_id;
        $.post(commonval+"/PendingOrder",postArray,function(data){
            if(data.status == 1){
                //显示redPoint
                if(data.data.wait_order == 1){
                    $("footer section:nth-child(2) img:nth-child(2)").css("display","inherit");
                    $("footer section:nth-child(2) p").css("margin-top","-43px");
                }
            }
        })
    }
});
//判断显示下载链接
$(document).ready(function(){
    var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if(isAndroid||isiOS){
        $(".download").css("display","none");
    }
    var share = getQueryString("share");
    console.log(share);
    if(share == 1){
        $(".download img").css("display","block");
        $(".download").css("display","block");
    }
});

